
import animModal from '/util/items';

const canvasComponent = [
  {
      icon: '/image/canvas.png',
      title: '画布',
      entitle: 'Canvas',
      page: 'canvas',
  },
  {
      icon: '/image/Other.png',
      title: '其他',
      entitle: 'Other',
      subs:[
          {
            title:"其他",
            entitle:"Others",
            page:"others",

          },
          {
            title:"富文本",
            entitle:"RichText",
            page:"rich-text"

          },
          {
            title:"上拉刷新",
            entitle:"pullLoading",
            page:"pullLoading"

          },
          // {
          //     title: '滑动视图',
          //     entitle: 'Swiper',
          //     page: 'swiper',
          // },
        ],
  },
  {
      icon: '/image/api.png',
      title: 'API',
      entitle: 'API',
      subs:[
          {
            title:"开放接口",
            entitle:"Open API",
            page:"api",

          },
          {
            title:"界面",
            entitle:"Interface",
            page:"interface"

          },
          {
            title:"设备",
            entitle:"Device",
            page:"device"
          },
          {
              title: '网络',
              entitle: 'Network',
              page: 'network',
          },
          {
              title: '媒体',
              entitle: 'Media',
              page: 'media',
          },
          {
              title: '位置',
              entitle: 'Location',
              page: 'location',
          },
          {
              title: '缓存',
              entitle: 'Storage',
              page: 'storage',
          },
          {
              title: '扫码',
              entitle: 'Scan',
              page: 'scan',
          },{
              title: '自定义分享',
              entitle: 'onShareAppMassage',
              page: 'onShareAppMessage',
          },
        ],
  },
];

Page({
  ...animModal.animOp,
  data: {
    ...animModal.data,
    pageName: 'index/index',
    pageInfo: {
      pageId: 0,
    },
    hidden: true,
    curIndex: 0,
    myarr:{
      onItemTap:'onMyGridItemTap',
      onChildItemTap: 'onMyChildItemTap',
      list:[
        {
          icon:"/image/view.png",
          title:"我的视图容器",
          entitle:"View",
          subs:[
            {
              title:"基础试图",
              entitle:"View",
              page:"view",

            },
            {
              title:"滚动视图",
              entitle:"ScrollView",
              page:"scroll-view"

            },
            {
                title: '滑动视图',
                entitle: 'Swiper',
                page: 'swiper',
            },
          ],

        },
        {
          icon:"/image/basic.png",
          title:"我的基础内容",
          entitle:"basic content",
          subs:[
            {
            title:"文字",
            entitle:"Text",
            page:"text"
            },
            {
            title:"图标",
            entitle:"Icon",
            page:"icon"
            },
            {
            title:"进度条",
            entitle:"Progress",
            page:"progress"
            },
          ],

        },{
          icon: '/image/form.png',
          title: '表单组件',
          entitle: 'Form',
          subs: [
            {
              title: '按钮',
              entitle: 'Button',
              page: 'button',
            },
            {
              title: '复选框',
              entitle: 'Checkbox',
              page: 'checkbox',
            },
            {
              title: '表单',
              entitle: 'Form',
              page: 'form',
            },
            {
              title: '文本输入',
              entitle: 'Input',
              page: 'input',
            },
            {
              title: '标签',
              entitle: 'Label',
              page: 'label',
            },
            {
              title: '选择器视图',
              entitle: 'PickerView',
              page: 'picker-view',
            },
            {
              title: '选择器',
              entitle: 'Picker',
              page: 'picker',
            },
            {
              title: '单选框',
              entitle: 'Radio',
              page: 'radio',
            },
            {
              title: '滑动条',
              entitle: 'Slider',
              page: 'slider',
            },
            {
              title: '开关',
              entitle: 'Switch',
              page: 'switch',
            },
            {
              title: '多行输入',
              entitle: 'Textarea',
              page: 'textarea',
            },
          ],
          }, {
            icon: '/image/feedback.png',
            title: '操作反馈',
            entitle: 'Feedback',
            subs: [
              {
                title: '动作面板',
                entitle: 'ActionSheet',
                page: 'action-sheet',
              },
              {
                title: '对话框',
                entitle: 'Modal',
                page: 'modal',
              },
              {
                title: '轻提示',
                entitle: 'Toast',
                page: 'toast',
              },
              {
                title: '加载提示',
                entitle: 'Loading',
                page: 'loading',
              },
            ],
          }, {
            icon: '/image/navigator.png',
            title: '导航',
            entitle: 'Navigator',
            page: 'navigator',
          }, {
            icon: '/image/media.png',
            title: '媒体组件',
            entitle: 'Media', page: 'image',
          },
          ...canvasComponent,
      ],

    },


  //业务组件部分
   mybiz: {
    onItemTap: 'onBizGridItemTap',
    list: [{
      icon: '/image/biz_collapse.png',
      title: '折叠面板',
      entitle: 'Collapse',
      page: '/page/biz/pages/collapse/index',
    }, {
      icon: '/image/biz_dropdown.png',
      title: '下拉菜单',
      entitle: 'Dropdown',
      page: '/page/biz/pages/dropdown/index',
    }, {
      icon: '/image/biz_errorview.png',
      title: '通用错误页',
      entitle: 'ErrorView',
      page: '/page/biz/pages/error-view/index',
    }, {
      icon: '/image/biz_grid.png',
      title: '宫格',
      entitle: 'Grid',
      page: '/page/biz/pages/grid/index',
    }, {
      icon: '/image/biz_list.png',
      title: '列表',
      entitle: 'List',
      page: 'list/list',
    }, {
      icon: '/image/biz_tag.png',
      title: '标签',
      entitle: 'Tag',
      page: '/page/biz/pages/tag/index',
    }],
  },

  myapi:{
    onItemTap: 'onApiGridItemTap',
    onChildItemTap: 'onApiChildItemTap',
    list: [
      //API->开放接口 
      {
        icon: '/image/api_open.png',
        title: '开放接口',
        entitle: 'Open API',
        subs: [{
          title: '获取授权码',
          entitle: 'getAuthCode',
          page: 'get-auth-code'
        }, {
          title: '电话',
          entitle: 'callUsers/showCallMenu/checkBizCall',
          page: 'phone'
        },
          {
            title: '发起支付',
            entitle: 'tradePay',
            page: 'request-payment'
          }
        ],
      },
      // API->页面
      {
        icon: '/image/api_view.png',
        title: '界面',
        entitle: 'Interface',
        subs: [{
          title: '警告框',
          entitle: 'alert',
          page: '../alert/alert'
        }, {
          title: '确认框',
          entitle: 'confirm',
          page: '../confirm/confirm'
        }, {
          title: '弱提示',
          entitle: 'toast',
          page: '../toast/toast'
        }, {
          title: '加载提示',
          entitle: 'loading',
          page: '../loading/loading'
        }, {
          title: '操作菜单',
          entitle: 'showActionSheet',
          page: '../action-sheet/action-sheet'
        }, {
          title: '设置界面导航栏',
          entitle: 'setNavigationBar',
          page: '../set-navigation-bar/set-navigation-bar'
        },
        // {
        //   title: '设置 optionMenu',
        //   entitle: 'setOptionMenu',
        //   page: '../option-menu/option-menu'
        // },
        {
          title: '页面跳转',
          // 180413去除redirectTo提升（因为目前不存在））
          entitle: 'navigateTo, navigateBack, switchTab, reLaunch',
          page: '../navigator/navigator'
        },
        // {
        //   title: '下拉刷新',
        //   entitle: 'pullDownRefresh',
        //   page: '../pull-down-refresh/pull-down-refresh'
        // },
        {
          title: '创建动画',
          entitle: 'createAnimation',
          page: '../animation/animation'
        }, {
          title: '创建绘画',
          entitle: 'createCanvasContext',
          page: '../canvas/canvas'
        },
        //  {
        //   title: '联系人',
        //   entitle: 'choosePhoneContact, chooseAlipayContact',
        //   page: '../contact/contact'
        // },
        {
          title: '选择日期',
          entitle: 'datePicker',
          page: '../date-picker/date-picker'
        },
        {
          title: '滚动页面',
          entitle: 'pageScrollTo',
          page: '../page-scroll-to/page-scroll-to'
        },
        {
          title: '节点位置',
          entitle: 'createSelectorQuery',
          page: '../create-selector-query/create-selector-query'
        },
        {
          title: '隐藏键盘',
          entitle: 'hideKeyboard',
          page: '../keyboard/keyboard'
        },
        ]
      },
      // API->设备
       {
        icon: '/image/api_device.png',
        title: '设备',
        entitle: 'Device',
        subs: [
          {
            api: 'getNetworkType',
            title: '获取手机网络状态',
            entitle: 'getNetworkType',
            page: '../get-network-type/get-network-type'
          },
          {
            title: '获取手机系统信息',
            entitle: 'getSystemInfo',
            page: '../get-system-info/get-system-info'
          },
          {
            title: '震动',
            entitle: 'vibrate',
            page: '../vibrate/vibrate'
          },
          {
            title: '打电话',
            entitle: 'makePhoneCall',
            page: '../make-phone-call/make-phone-call'
          },
          {
            title: '剪贴板',
            entitle: 'clipboard',
            page: '../clipboard/clipboard'
          },
          {
            title: '获取基础版本库',
            entitle: 'SDKVersion',
            page: '../sdk-version/sdk-version'
          },
        ]
      },
      //API->网络
      {
        icon: '/image/api_network.png',
        title: '网络',
        entitle: 'Network',
        subs: [{
          api: 'httpRequest',
          title: '发起一个请求',
          entitle: 'request',
          page: '../request/request'
        },
        {
          title: 'WebSocket',
          entitle: 'WebSocket',
          page: '../websocket/websocket'
        },
        {
          api: 'uploadFile',
          title: '上传文件',
          entitle: 'Upload File',
          page: '../upload-file/upload-file'
        }, {
          title: '下载文件',
          entitle: 'Download File',
          page: '../download-file/download-file'
        }]
      },
      //API->媒体
      //API->位置
      //API->缓存
      //API->扫码
      //API->自定义分享
      //API->...

    ]
    

  }
        
  },

  //网格grid主元素Item的点击事件
  onMyGridItemTap(e){
    // console.log('index=',e.currentTarget.dataset.index)
    // console.log("网格grid主元素Item的点击事件onMyGridItemTap")
    // console.log(this.data)
    const curIndex = e.currentTarget.dataset.index;
    const childList = this.data.myarr.list[curIndex];
     if (childList.subs) {
       console.log(childList.subs)
        this.setData({
          hidden: !this.data.hidden,
          curIndex,
        });
      //创建遮罩层显示，具体怎么实现没理解，先用再说（来自/util/items）
      this.createMaskShowAnim();
      //创建内容展示动画，不理解，先用着（来自/util/items）
      this.createContentShowAnim();
    } else {
      this.onMyChildItemTap({
        currentTarget: {
          dataset: { page: childList.page },
        },
      });
    }

  },
  //网格grid子元素元素subs的点击事件
  onMyChildItemTap(e){
    // console.log("网格grid子元素元素subs的点击事件onMyChildItemTap")
    // console.log('page:',e.currentTarget.dataset.page)
    const { page } = e.currentTarget.dataset;
    //钉钉跳转页面
    dd.navigateTo({
      url: `${page}/${page}`,
    });
  },
  //关闭弹出动画
  onModalCloseTap() {
    console.log("关闭弹出动画onModalCloseTap")
    //创建遮罩隐藏动画
    this.createMaskHideAnim();
    //创建内容隐藏动画
    this.createContentHideAnim();
    // 延时函数中设置hidden状态为隐藏
    setTimeout(() => {
      this.setData({
        hidden: true,
      });
    }, 210);
  },
  onBizGridItemTap(e){
    const page = this.data.mybiz.list[e.currentTarget.dataset.index].page;
    // console.log(page)
    dd.navigateTo({ url: page });
  },
  onLoad() {},
});